<template>
    <view>
        <van-cell-group>
            <van-field :value="valueName"  label="收货人" left-icon="friends" placeholder="姓名"  border="false" @change="onName"/>
            <van-field :value="valuePhone" type="number" label="手机号码" left-icon="phone" placeholder="11位手机号"  border="false" @change="onPhone"/>
           
             <van-field :value="valueAddress"  label="收货地址" left-icon="map-marked" placeholder="详细地址信息"  border="false" @change="onAddress"/>
        </van-cell-group>
        <van-toast id="van-toast" />
        <van-button class="mybtn" @click="save" size="large" color="linear-gradient(to bottom, #42c45e, #1fb40c)">保存</van-button>  
    </view>
</template>
<script>
import Toast from '../../wxcomponents/vant/dist/toast/toast'
const url = 'http://47.108.197.149:8081'
export default {
    data(){
        return{
            show:false,
            valueName:"",
            valuePhone:"",
            valueAddress:"",  
            userID:""          
        }
    },
    onLoad(){
        this.userID = getApp().globalData.userInfo[0].userId
        uni.request({
                url:url+'/app/wxUser/getAddress',
                method:'POST',
                data:{
                    id:this.userID
                },
                success:res =>{
                    this.valueName = res.data.user.consignee
                    this.valuePhone = res.data.user.phone
                    this.valueAddress = res.data.user.address
                }
        })
    },
    methods:{
        close(){
            this.show = false
        },
        onName(e){
            this.valueName = e.detail
        },
        onPhone(e){
            this.valuePhone = e.detail
        },
        onfocus(){
            this.show = true
        },
        onAddress(e){
            this.valueAddress = e.detail
        },
        save(){
            if(this.valueName&&this.valuePhone&&this.valueAddress != ""){
                Toast.success(`已保存收货信息~`)
                uni.request({
                url:url+'/app/wxUser/updateAddress',
                method:'POST',
                data:{
                    id:this.userID,
                    consignee:this.valueName,
                    phone:this.valuePhone,
                    address:this.valueAddress,
                },
                success:res =>{
                    // console.log(res)
                    Toast.success(`收货信息保存成功~`)
                }
        })
            }else{
                Toast.fail(`请完善收货信息~`)
            }
            
        }
    }
}

</script>
<style scoped>
   .mybtn{
       position: relative;
       top: 50rpx; 
   }
   .ss{
       color: #42c45e;
       color: #1fb40c;
   }
</style> 